package com.qingfeng.client.service;

import com.qingfeng.client.bean.OrderGoods;
import com.qingfeng.client.bean.OrderStore;
import com.qingfeng.client.bean.Trade;
import com.qingfeng.client.dao.OrderGoodsMapper;
import com.qingfeng.client.dao.OrderStoreMapper;
import com.qingfeng.client.dao.TradeMapper;
import com.qingfeng.client.util.TradeEnum;
import com.qingfeng.coupon.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zhangyuefei
 * @version 1.0
 * @date 2020/3/6 2:58 下午
 */
@Service
public class PayService {
    @Resource
    private TradeMapper tradeDAO;

    @Resource
    private OrderStoreMapper orderStoreDAO;

    @Resource
    private OrderGoodsMapper orderGoodsDAO;

    @Autowired
    private CouponService couponService;

    @Transactional
    public void paySuccess(String tradeCode,int totalPay,int payTime,String payCode){
        Trade tradeBean = tradeDAO.getByCode(tradeCode);
        tradeBean.setTradeStat(TradeEnum.TRADE_WAIT_SEND.getCode());
        tradeBean.setPayTime(payTime);
        tradeBean.setPaycode(payCode);
        tradeBean.setPayment(totalPay);
        tradeDAO.updateById(tradeBean);
        orderStoreDAO.updateStatAndPayTimeByCode(TradeEnum.TRADE_WAIT_SEND.getCode(),payTime,tradeBean.getCode());
        orderGoodsDAO.updateStatByTradeId(TradeEnum.TRADE_WAIT_SEND.getCode(),tradeBean.getId());
//        updateSellerBill(tradeCode, (long) totalPay);
        
        couponService.receiveCouponByPaySuccess(tradeBean);

    }



}
